﻿module Enferno.Public.Web.Components.Models {

    export class AddressModel {
        public careOf: string;
        public city: string;
        private _country: string;
        private _countryId: number;
        public line1: string;
        public line2: string;
        public zip: string;

        constructor();
        constructor(serverObject: any);
        constructor(serverObject?: any) {
            if (serverObject != null) {
                this.createFromServerObject(serverObject);
            }
        }
  
        public getCountry(): string {
            return this._country;
        }

        public setCountry(country: string) {
            this._country = country;
        }

        public getCountryId(): number {
            return this._countryId;
        }

        public setCountryId(countryId: number) {
            this._countryId = countryId;
        }

        private createFromServerObject(serverObject: any) {
            this.careOf = serverObject.careOf;
            this.city = serverObject.city;
            this._country = serverObject.country;
            this._countryId = serverObject.countryId;
            this.line1 = serverObject.line1;
            this.line2 = serverObject.line2;
            this.zip = serverObject.zip;
        }

        public serialize(): any {
            var obj: any = {};
            obj.careOf = this.careOf;
            obj.city = this.city;
            obj.country = this._country;
            obj.countryId = this._countryId;
            obj.line1 = this.line1;
            obj.line2 = this.line2;
            obj.zip = this.zip;

            return obj;
        }

        public isValid(): boolean {
            return this.city != null && this.city != ""
                && this.line1 != null && this.line1 != ""
                && this.zip != null && this.zip != ""
                && this._country != null && this._country != "";
                //&& this._countryId != null && this._countryId != 0;
        }
    }
}  